package blockchain

type BlockChain struct {
	Blocks []*Block
}

func (bc *BlockChain) AddBlock(data string) {
	// 修正参数顺序：第一个参数是数据，第二个参数是前一个区块的哈希
	prevBlock := bc.Blocks[len(bc.Blocks)-1]
	newBlock := CreateBlock([]byte(data), prevBlock.Hash)
	bc.Blocks = append(bc.Blocks, newBlock)
}

func CreateBlockChain() *BlockChain {
	blockchain := BlockChain{}
	blockchain.Blocks = append(blockchain.Blocks, GenesisBlock())
	return &blockchain
}